package com.remainder.common.core.exception;

import com.remainder.common.core.constant.Constants;
import com.remainder.common.core.constant.RetConst;

/**
 * api业务异常
 * <p>
 * 谨慎使用该类，为了性能原因，该类重写了fillInStackTrace，所以不会打印异常的堆栈信息
 * </p>
 *
 * @author weiyoulong
 */
public class ApiBusinessException extends BusinessException {
    private static final long serialVersionUID = 1L;

    /**
     * 响应码
     */
    private final int code;

    private final String errorCode;

    public ApiBusinessException(RetConst retConst) {
        this(Constants.WARN, retConst.getCode(), retConst.getDesc());
    }

    public ApiBusinessException(String message) {
        this(Constants.WARN, message);
    }

    public ApiBusinessException(Integer code, String message) {
        this(code, null, message);
    }

    public ApiBusinessException(Integer code, String errorCode, String message) {
        super(message);
        this.errorCode = errorCode;
        this.code = code;
    }

    /**
     * 获取响应码
     */
    public int getCode() {
        return code;
    }

    /**
     * 获取响应码
     */
    public String getErrorCode() {
        return errorCode;
    }

    /**
     * 不打印堆栈信息
     *
     * @return Throwable
     */
    @Override
    public synchronized Throwable fillInStackTrace() {
        return this;
    }

}
